package com.wuji.blog.controller;

import com.wuji.blog.common.aop.LogAnnotation;
import com.wuji.blog.common.cache.CacheAnnotation;
import com.wuji.blog.pojo.param.ArticleParam;
import com.wuji.blog.pojo.param.PageParam;
import com.wuji.blog.service.ArticleService;
import com.wuji.blog.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @作者 wangj
 * @日期 2022/1/20 14:52
 * @描述 controller
 **/
@RestController
@RequestMapping("articles")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    /**
     * 首页 文章列表
     * @param pageParam
     * @return
     */
    @PostMapping
    @LogAnnotation(module="文章",operator="获取文章列表")
    @CacheAnnotation(name = "listArticle")
    public Result listArticle(@RequestBody PageParam pageParam){
//        int i = 10/0;
        return articleService.listArticle(pageParam);
    }

    /**
     * 首页 最热文章
     * @return
     */
    @PostMapping("hot")
    @CacheAnnotation(name = "hot_article")
    public Result hotArticle(){
        int limit = 5;
        return articleService.hotArticle(limit);
    }

    /**
     * 首页 最新文章
     * @return
     */
    @PostMapping("new")
    @CacheAnnotation(name = "news_article")
    public Result newArticles(){
        int limit = 5;
        return articleService.newArticles(limit);
    }

    /**
     * 首页 最新文章
     * @return
     */
    @PostMapping("listArchives")
    public Result listArchives(){
        return articleService.listArchives();
    }


    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long articleId){
        return articleService.findArticleById(articleId);
    }
    //接口url：/articles/publish
    //
    //请求方式：POST
    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParam articleParam){

        return articleService.publish(articleParam);
    }
}
